#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char **argv, char **envp) {
	if (argc != 2) return 1;

	char *filename = argv[1];
	// Replace existing file, or create a new one with
	// permissions 644 if nonexistant.
	int fd = open(filename, O_CREAT
	                      | O_WRONLY
	                      | O_TRUNC,
	                                 S_IRUSR
	                               | S_IWUSR
	                               | S_IRGRP
	                               | S_IROTH);

	// Create a 100 byte buffer full of 0xAAAAAAA...
	char buf[100];
	int i = 0;
	while(i < 99) {
		buf[i] = 0xAA;
		i++;
	}

	// Doing what assignment description says:
	write(fd, buf, 100);
	lseek(fd, 40000, SEEK_SET);
	write(fd, buf, 100);
	close(fd);

	return 0;
}
